<template>
	<el-container>
		<el-main class='x-main-edit'>
			<el-form ref="form" :rules="form_rules" :model="form" size="mini" label-width="15%">
				<el-tabs type="border-card" v-model="page_tag">
					<!---->
					<!---->
					<el-tab-pane :label="page_info.title" name="1">
						<el-form-item label="用户">
							<el-checkbox-group v-model="form.user">
								<el-checkbox v-for="(val,key) in page_info.list_user" :label="val.suser_id" :key="val.suser_id">
									{{val.suser_name}}
								</el-checkbox>
							</el-checkbox-group>
							<el-button type="primary" @click="funcGenPlan" size="mini">生成任务计划</el-button>
						</el-form-item>
						<el-form-item label="任务计划" prop="task_plan">
							<el-input type="textarea" :rows="5" class="x-input-60" v-model="form.task_plan"/>
						</el-form-item>
					</el-tab-pane>
					<!---->
					<!---->
					<el-tab-pane v-if="false" label="模板" name="2">
						<el-form-item label="应用模板" prop="reply_app_file" ref="reply_app_file">
							<el-col :span="6">
								<el-input v-model="form.reply_app_file" placeholder="默认：t_001"/>
							</el-col>
						</el-form-item>
					</el-tab-pane>
					<!---->
					<!---->
				</el-tabs>
				<!---->
				<!---->
			</el-form>
			<!---->
			<!---->
			<!-- 按钮部分 -->
			<div class="save_wrap">
				<el-button @click="g_page.funcBack" size="mini">返回</el-button>
				<el-button type="success" @click="g_page.funcSave" size="mini">保存</el-button>
				<el-checkbox v-if="page_info.is_admin_edit" style="margin-left: 10px;" label="保存后停留" v-model="checked"/>
			</div>
			<!---->
			<!---->
			<!---->
		</el-main>
	</el-container>
</template>

<script>
	export default {
		data() {
			let page_data = { dialogVisible: false }
			//
			page_data = this.g_cc.funcGetInitData(page_data)
			//
			return page_data
		},
		mounted() {
			console.log('mounted', this._uid)
			console.log(this.$route.query)

			this.g_page.funcSetVue(this)
			//
			this.g_page.funcSetApiUrlEdit('/xadmin/sh/sh__task__edit')
			this.g_page.funcSetApiUrlSave('/xadmin/sh/sh__task__edit/save')
			let page = this
			//验证
			this.form_rules = {
				__test: [{
					required: true,
					message: '请输入原密码',
					trigger: 'blur'
				}]
			}

			let data = this.$route.query
			this.g_page.funcEdit(data)
		},
		methods: {
			//保存之前
			funcSaveBefore(data) {
				console.log('funcSaveBefore', data)

				return data
			},
			funcGenPlan() {
				console.log('funcGenPlan', this.form.user)
				let plan = []
				for (let key in this.form.user) {
					let user_id = this.form.user[key]

					let entity_user = this.page_info.list_user[user_id]

					plan.push({
						'ck': entity_user.suser_key,
						'api_url': entity_user.suser_task_api_url
					})
				}

				this.form.task_plan = JSON.stringify(plan)
			}
			////////////////
		}
	}
</script>

<style scoped>
	.item {
		margin-bottom: 5px;
	}
</style>
